package util;

import javax.servlet.http.HttpSession;

import manager.UserManager;

import data.dao.UserDAOException;
import data.dto.UserDTO;
import data.searchdto.UserTypeSearchDTO;

public class CurrentUser {

	private short userId = 0;
	private String userName;

	// public short getUserId() {
	// return userId;
	// }
	//
	// public void setUserId(short userId) {
	// this.userId = userId;
	// }
	//
	// public String getUserName() {
	// return userName;
	// }
	//
	// public void setUserName(String userName) {
	// this.userName = userName;
	// }

	public CurrentUser(short userId, String userName) {
		super();
		this.userId = userId;
		this.userName = userName;
	}

	public short getUserId() {
		return userId;
	}

	public void setUserId(short userId) {
		this.userId = userId;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public static UserDTO getCurrentUser(HttpSession session){
		return (UserDTO)session.getAttribute("user");
	}
	
	public static boolean isAdmin(UserDTO user){
		boolean isAdmin = false;
		
		UserManager userManager = new UserManager();
		try {
			if (userManager.findUserType(new UserTypeSearchDTO(user.getUserType(), "")).getName().equalsIgnoreCase("admin")){
				isAdmin = true;
			}
		} catch (UserDAOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return isAdmin;
	}
	
}
